<?php
/**
 * JoiTemplates - ���������� ��� ������ � ��������� �����������
 *
 * Core Class
 *
 * @version 1.0
 * @package JoiTemplates
 * @filename joiTemplates.class.php
 * @author JoostinaTeam
 * @copyright (C) 2008-2009 Joostina Team
 * @license GNU GPL 2.0. ����������, �� �������� ��������� �� ��������� ����. �������.
 *
 **/
DEFINE('JOITEMPLATES', '1');

class joiTemplates {

    var $component = null;
    var $page_type = null;
    var $dir_type = null;
    var $template_dir = null;
    var $template_file = null;
    
    function joiTemplates($component) {
	$this->component = $component;
    }
    
    function get_template($page_type, $dir_type = 0, $template_file = 'default.php') {

	$config = & Jconfig::getInstance();
	$absolute_path = Jconfig::getInstance()->config_absolute_path;

	$this->page_type = $page_type;
	$this->dir_type = $dir_type;


	if ($this->dir_type == 0) {
	    $this->template_dir = $this->get_system_path($this->page_type);
	}
	else {
	    $this->template_dir = $this->get_currtemplate_path($this->page_type);
	}


	if (is_file($absolute_path . DS . $this->template_dir . DS . $template_file)) {
	    $this->template_file = $absolute_path . DS . $this->template_dir . DS . $template_file;
	    return true;
	}
	else {
	    return false;
	}
    }
    
    function get_system_path($page_type) {
	$template_dir = self::get_template_dir($page_type);
	$system_path = 'components' . DS . $this->component . DS . 'view' . DS . $template_dir;
	return $system_path;
    }
    
    function get_currtemplate_path($page_type) {
	$mainframe = new mosMainFrame(null, null, null, false);

	$template_dir = self::get_template_dir($page_type);
	$currtemplate_path = 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . $this->component . DS . $template_dir;
	return $currtemplate_path;
    }
    
    function get_template_dir($page_type) {
	$dir = str_replace('_', '/', $page_type);
	return $dir;
    }
}